<?php

/**
 * 
 */
namespace User\Controller;
use Common\Controller\UBaseController;
class ActiveController extends UBaseController {
	
	
	function _initialize() {
		parent::_initialize();
		
	  	$this->_check_login();  //验证是否登录
		$this->_check_status();  //验证是否经过审核
		$this->_check_member();//验证是否是个人用户
	
	
	
	}

	public function _check_status(){
	
		if($this->u[email_status]==1){
	
			$this->success("已经激活成功！",U("User/Center/index"));
		}
	
	
	}

	function index(){
		$this->display("");
		
		
		
	}
	
	function doactive(){
		
	
			$this->_send_to_active();
			
			
			$this->do_loginout();
			$this->success('激活邮件发送成功，激活请重新登录！',U("User/Public/login"));
			
			
		
		
	
		
	}
	
	
	//邮箱中的激活请求
	function active(){
		$hash=I("get.hash","");
		if(empty($hash)){
			$this->error("激活码不存在");
		}
	
		$users_model=M("Users");
		$find_user=$users_model->where(array("user_activation_key"=>$hash))->find();
	
		if($find_user){
			$result=$users_model->where(array("user_activation_key"=>$hash))->save(array("user_activation_key"=>"","email_status"=>1));
	
			if($result){
				$this->do_loginout();
				$this->success("用户激活成功，请重新登录！",U("User/Public/login"));
			}else{
				$this->error("用户激活失败!");
			}
		}else{
			$this->error("用户激活失败，激活码无效！");
		}
	
	
	}
	
	function email_rest(){
		
		if(IS_POST){
		
		$data=array("id"=>$this->u[id],"email"=>I('post.email'),"email_status"=>0);
		
		if(!M("Users")->save($data)){
			$this->error("修改失败！");
		};
		$this->do_loginout();
		$this->_send_to_active();
		$this->success('激活邮件发送成功，激活请重新登录！',U("User/Public/login"));
	}else{
		$this->display(":email_rest");
		
	}
		
	}
	
	

}
?>
